/* CoralCube | Massively Multiplayer Online Role-Playing Game(MMORPG) Emulator.
|* 
|* Copyright (C) 2008-2010 CoralCube <http://www.CoralCube.com/>
|*
|* This program is free software. You can redistribute it and/or modify it under the terms of 
|* the GNU General Public License as published by the Free Software Foundation, either 
|* version 2 of the License.
|*
|* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, 
|* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
|* See the GNU General Public License for more details.
|*
|* You should have received a copy of the GNU General Public License along with this program. 
|* If not, see <http://www.gnu.org/licenses/>.
|*/

#include "ConfigDatabase.h"

bool ConfigDatabaseConnection::Open()
{
    if (!MySQLConnection::Open())
        return false;

    m_stmts.resize(MAX_CONFIGDATABASE_STATEMENTS);
    /*
    ##################################
    LOAD YOUR PREPARED STATEMENTS HERE
    ##################################
    */

    return true;
}

ConfigDatabaseSettings::ConfigDatabaseSettings() { }
ConfigDatabaseSettings::~ConfigDatabaseSettings() { }

const char* ConfigDatabaseSettings::ToString(bool getBool)
{
    return (const char)getBool ? "1 (true)" : "0 (false)";
}

const char* ConfigDatabaseSettings::StringEmpty(const char* getString)
{
    std::string tostring = getString;
    return tostring.empty() ? "<empty>" : getString;
}

void ConfigDatabaseSettings::setIntConfig(ConfigDatabaseInt index, uint32 value, const char token)
{
    if (index < INT_CONFIG_DB_VALUE_COUNT)
    {
        switch(token)
        {
        case '|':
            c_int_configs[index] |= value;
            break;

        case '+':
            c_int_configs[index] += value;
            break;

        default:
        c_int_configs[index] = value;
            break;
        }
    }
}

uint32 ConfigDatabaseSettings::getIntConfig(ConfigDatabaseInt index) const
{
    return index < INT_CONFIG_DB_VALUE_COUNT ? c_int_configs[index] : 0;
}

void ConfigDatabaseSettings::setBoolConfig(ConfigDatabaseBool index, bool value)
{
    if (index < BOOL_CONFIG_DB_VALUE_COUNT)
        c_bool_configs[index] = value;
}

bool ConfigDatabaseSettings::getBoolConfig(ConfigDatabaseBool index) const
{
    return index < BOOL_CONFIG_DB_VALUE_COUNT ? c_bool_configs[index] : 0;
}
